<table class="table table-hover" id="goods-comment-list">
    <tr>
        <th style="border:none;">商品缩略图</th>
        <th style="border:none;">商品标题</th>
        <th style="border:none;">评论用户</th>
        <th style="border:none;">用户头像</th>
        <th style="border:none;">评论内容</th>
        <th style="border:none;">评论图片</th>
        <th style="border:none;">评论时间</th>
        <th style="border:none;">评论打星</th>
        <th style="border:none;">点赞数量</th>
        <th style="border:none;">好评/中评/差评</th>
        <th style="border:none;">是否回复</th>
        <th style="border:none;">操作</th>
    </tr>
    <?php if($data):?>
    <?php foreach($data as $v):?>
        <tr>
            <td style="line-height: 40px"><img src="/<?php echo ltrim(cutUrl($v['goods_thumb'],80,40),'/')?>" alt=""></td>
            <td style="line-height: 40px">
                <span data-toggle="tooltip" data-placement="top" title="<?php echo $v['goods_title']?>">
                    <?php echo str_cut($v['goods_title'],20,'...')?>
                </span>
            </td>
            <td style="line-height: 40px">
                <?php

                    if ( $v['user_info']['nicname'] )
                    {
                        echo $v['user_info']['nicname'];

                    } elseif($v['user_info']['username']) {

                        echo $v['user_info']['username'];

                    }

                ?>
            </td>
            <td style="line-height: 40px"><img style="border-radius: 50%" src="/<?php echo ltrim(cutUrl($v['user_info']['avatar'],40,40),'/')?>" alt=""></td>
            <td style="line-height: 40px">
                <span data-toggle="tooltip" data-placement="top" title="<?php echo $v['content']?>">
                    <?php echo str_cut($v['content'],20,'...');?>
                </span>
            </td>
            <td style="line-height: 40px">
                <?php if ( $v['images'] ):?>
                    <?php
                        foreach($v['images'] as $key=>$val){
                            $pic[$key]['alt'] = '';
                            $pic[$key]['src'] = '/'.ltrim($val,'/');
                            $pic[$key]['thumb'] = '/'.ltrim(cutUrl($val,200,0),'/');
                        }
                    ?>
                    <a href="javascript:;" data-pic=<?php echo json_encode($pic);?> class="btn btn-default btn-xs images">查看图片</a>
                <?php else:?>
                    无图片
                <?php endif;?>
            </td>
            <td style="line-height: 40px">
                <?php echo $v['create_time'];?>
            </td>
            <td style="line-height: 40px">
                <?php for( $i = 1; $i <= $v['star']; $i++ ):?>
                    <i class="fa fa-star orange"></i>
                <?php endfor;?>
            </td>
            <td style="line-height: 40px">
                <?php echo $v['likes'];?>
            </td>
            <td style="line-height: 40px">
                <?php

                    $types = [
                        1 => '<span class="green">好评</span>',
                2 => '<span class="orange">中评</span>',
                3 => '<span class="red">差评</span>',
                ];
                echo $types[$v['type']];
                ?>
            </td>
            <td style="line-height: 40px">
                <?php if($v['reply']):?>
                    <span class="green">已回复</span>
                <?php else:?>
                    <span class="red">未回复</span>
                <?php endif;?>
            </td>
            <td style="line-height: 40px" data-id="<?php echo $v['id']?>">
                <a href="javascript:;" class="btn btn-danger btn-xs radius-none delete">删除</a>
                <a href="javascript:;" class="btn btn-success btn-xs reply radius-none">回复</a>
            </td>
        </tr>
        <?php if($v['reply']):?>
                <tr>
                    <th colspan="1" style="border:none;">回复人</th>
                    <th colspan="7" style="border:none;">回复内容</th>
                    <th colspan="3" style="border:none;">回复时间</th>
                    <th colspan="1" style="border:none;">操作</th>
                </tr>
            <?php foreach($v['reply'] as $val):?>
                <tr>
                    <td colspan="1"><?php echo $val['username']?></td>
                    <td colspan="7"><?php echo $val['content']?></td>
                    <td colspan="3"><?php echo date('Y-m-d H:i:s',$val['create_time'])?></td>
                    <td colspan="1">
                        <a href="javascript:;" data-id="<?php echo $val['id']?>" class="btn btn-danger btn-xs radius-none delete-reply">删除</a>
                    </td>
                </tr>
            <?php endforeach;?>
        <?php endif;?>
    <?php endforeach;?>
    <?php else:?>
    <tr>
        <td colspan="12" style="text-align: center; font-size: 20px; line-height: 50px">

            没有找到符合条件的数据!

        </td>
    </tr>
    <?php endif;?>
</table>
<div role="group" data-total="<?php echo $total?>" data-page="<?php echo $page?>" data-nums="<?php echo $nums?>" data-src="<?php echo U('Admin/Goods/GoodsComment/lists');?>"  class="btn-group" id="_pages"></div>
<script>

    $(function(){

        //工具提示
        $('[data-toggle="tooltip"]').tooltip();

        //分页参数
        var options = {

            'type': '<?php echo $type?>'

        }
        Admin.pages(options);

        //回复评论
        $('.reply').unbind('click');
        $('.reply').click(function(){

            var id = $(this).parent().data('id');

            layer.prompt({title: '请输入回复内容', formType: 2}, function(content){

                $.ajax({

                    url: '<?php echo U("Admin/Goods/GoodsComment/reply")?>',
                    type: 'post',
                    data: {
                        'id'        :id,
                        'content'    :content
                    },
                })
                .done(function(result){

                    var data = {}
                    var url = '';
                    if(result.code == 200){

                        var data = options;
                        data.page = "<?php echo $page?>";

                        url = '<?php echo U("Admin/Goods/GoodsComment/lists")?>';

                    }

                    showMessage(result.msg,result.code,url,data,2000);

                })
            });


        })
        //删除
        $('.delete').unbind('click');
        $('.delete').click(function(){

            var id = $(this).parent().data('id');

            layer.msg('确定删除吗?不可恢复哦!', {
                time: 0 //不自动关闭
                ,btn: ['确定', '关闭']
                ,yes: function(index){
                    layer.close(index);

                    $.ajax({

                        url: '<?php echo U("Admin/Goods/GoodsComment/delete")?>',
                        type: 'post',
                        data: {'id':id}

                    })
                    .done(function(result){

                                var url = '';
                                var data = {};
                                if ( result.code == 200 ) {

                                    url = '<?php echo U("Admin/Goods/GoodsComment/lists")?>';
                                    data = options;
                                    data.page = "<?php echo $page?>";

                                }
                                showMessage(result.msg,result.code,url,data,2000);

                    })
                }
            });

        });
        //删除评论回复
        $('.delete-reply').unbind('click');
        $('.delete-reply').click(function(){

            var id = $(this).data('id');

            layer.msg('确定删除吗?不可恢复哦!', {
                time: 0 //不自动关闭
                ,btn: ['确定', '关闭']
                ,yes: function(index){
                    layer.close(index);

                    $.ajax({

                        url: '<?php echo U("Admin/Goods/GoodsComment/deleteReply")?>',
                        type: 'post',
                        data: {'id':id}

                    })
                    .done(function(result){

                                var url = '';
                                var data = {};
                                if ( result.code == 200 ) {

                                    url = '<?php echo U("Admin/Goods/GoodsComment/lists")?>';
                                    data = options;
                                    data.page = "<?php echo $page?>";

                                }
                                showMessage(result.msg,result.code,url,data,2000);

                    })
                }
            });

        });


        //查看评论图像
        $('.images').unbind('click');
        $('.images').click(function(){

            var pic = $(this).data('pic');
            //var title = $(this).data('title');

            var options = {

                'title' : '',
                'id'    : 1,
                'start' : 0,
                'data'  : pic,

            }
            layer.photos({
                photos: options
            });
        });
    })

</script>